package bera.lee.memorycard;

import bera.lee.memorycard.R;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ToggleButton;

/**
 *<pre>
 * <b><font color="blue">Setting</font></b>
 * </pre>
 * 
 *<pre>
 * <b>&nbsp;--描述说明--</b>
 * </pre>
 * 
 * <pre></pre>
 * 
 * <pre>
 * <b>--样例--</b>
 *   Setting obj = new Setting();
 *   obj.method();
 * </pre>
 * 
 * JDK版本：JDK1.4
 * 
 * @author <b>beralee</b>
 */
public class Setting extends Activity {
	private ToggleButton t1;

	private ToggleButton t2;

	private DbAdapter mDbHelper;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting);

		mDbHelper = new DbAdapter(this);
		mDbHelper.open();
		t1 = (ToggleButton) findViewById(R.id.toggle1);
		t2 = (ToggleButton) findViewById(R.id.toggle2);
		if (Config.OPEN_BGM) {
			t1.setChecked(true);
		}
		if (Config.OPEN_MUSIC) {
			t2.setChecked(true);
		}

		t1.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				if (Config.OPEN_BGM) {
					Config.OPEN_BGM = false;
					mDbHelper.updateValue("openbgm", "0");
				} else {
					Config.OPEN_BGM = true;
					mDbHelper.updateValue("openbgm", "1");
				}
			}
		});
		t2.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				if (Config.OPEN_MUSIC) {
					Config.OPEN_MUSIC = false;
					mDbHelper.updateValue("openmusic", "0");
					MainMenu.music_song.release();

				} else {
					Config.OPEN_MUSIC = true;
					mDbHelper.updateValue("openmusic", "1");
					MainMenu.music_song=MediaPlayer.create(Setting.this, R.raw.music1);
					MainMenu.music_song.setLooping(true);
					MainMenu.music_song.start();

				}
			}
		});

	}
}
